<?php

declare(strict_types=1);

namespace App\Request;

use Hyperf\Validation\Request\FormRequest;

class FriendLinkRequest extends FormRequest
{
    protected array $scenes = [
        'add' => ['name',  'link_url', 'status', 'sort'],
        'edit' => ['id', 'name',  'link_url', 'status', 'sort'],
    ];
    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     */
    public function rules(): array
    {
        return [
            'id' => 'required|integer',
            'name' => 'required|min:2|max:200',
            'link_url' => 'url',
            'sort' => 'required|integer',
            'status' => 'required|integer',
        ];
    }

    /**
     * 获取已定义验证规则的错误消息
     */
    public function messages(): array
    {
        return [
            'id.required' => '参数错误-0',
            'id.integer' => '参数错误-1',
            'name.required' => '名称不能为空',
            'name.min' => '名称格式不正确',
            'name.max' => '名称格式不正确',
            'link_url.url' => '链接地址格式错误',
            'sort.required' => '排序格式错误-1',
            'sort.integer' => '排序格式错误-2',
            'status.required' => '状态格式错误-1',
            'status.integer' => '状态格式错误-2',
        ];
    }
}
